//
//  WmcPauseVideoRecordBtn.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/7/8.
//

import UIKit

extension WmcHomePauseRecordBtn {
    /// 录制状态
    enum RecordState: Int {
        /// 暂停
        case pause
        /// 继续
        case `continue`
        
        struct Info {
            var image: UIImage
            var title: String
        }
        
        var info: Info {
            switch self {
            case .pause: return .init(image: "home_tool_pause".wmc_image, title: "暂停")
            case .continue: return .init(image: "home_tool_continue".wmc_image, title: "继续录制")
            }
        }
    }
}

// MARK: - [WmcPauseVideoRecordBtn]

class WmcHomePauseRecordBtn: WmcTopImgBottomTextBtn {
    /// 事件Block
    var actionBlock: YPBlock.Action<WmcHomePauseRecordBtn>?
    
    /// 按钮状态
    var recordState: RecordState = .pause {
        didSet {
            imageView.image = recordState.info.image
            label.text = recordState.info.title
        }
    }

    /// 创建
    static func Create() -> WmcHomePauseRecordBtn {
        let btn = WmcHomePauseRecordBtn()
        btn.backgroundColor = .clear
        btn.font = 12.yp.uiFont(weight: .medium)
        btn.imgTextSpacing = 6
        btn.imgSize = 36
        btn.textColor = .black
        btn.yp.layoutWidthEqual(50.wmc_autoHor)
        btn.yp.addEvent { btn in
            btn.actionBlock?(btn)
            btn.clickState()
        }
        btn.recordState = .pause
        return btn
    }

    /// 递增事件
    func clickState() {
        let new = recordState.rawValue
        if let newCase = RecordState(rawValue: new + 1) {
            recordState = newCase
        } else {
            recordState = .pause
        }
    }
}
